package com.hisysteTopet.hisystepet.config;

import com.hisysteTopet.hisystepet.interceptors.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebAppConfingurer implements WebMvcConfigurer {
    //还可以通过extends WebMvcConfigurationSupport
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseSuffixPatternMatch(false);
    }

    //配置资源映射路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/templates/")
                .addResourceLocations("classpath:/static/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptor())
                .addPathPatterns("/userAndPet")
                .addPathPatterns("/userToFoster")
                .addPathPatterns("/userMessage")
                .addPathPatterns("/userRegistration")
                .addPathPatterns("/userToDeleteFoster")
                .addPathPatterns("/registration")
                .addPathPatterns("/userUpdatePasswordAndAddress")
                .addPathPatterns("/indentMessage")
                .addPathPatterns("/petPaging")
                .addPathPatterns("/insertIndentToPet")
                .addPathPatterns("/petLifeGoodsPaging")
                .addPathPatterns("/insertIndentToPetLifeGoods")
                .addPathPatterns("/indentToGoodsMessage")
                .addPathPatterns("/insertShowCartMessage")
                .addPathPatterns("/selectAllShopCartByUsername")
                .addPathPatterns("/selectMessageByIdAndClassify")
                .addPathPatterns("/findAllToUserMessage")
                .addPathPatterns("/noticeAllMessage")
                .addPathPatterns("/allFosterMessage")
                .addPathPatterns("/petManagement")
                .addPathPatterns("/petAllIndentMessage")
                .addPathPatterns("/lifeGoodsAllIndentMessage")
                .addPathPatterns("/updateNoticeMessage")
                .addPathPatterns("?updateNotice")
                .addPathPatterns("/insertNotice")
                .addPathPatterns("/updatePetMessage")
                .addPathPatterns("/deletePetMessage")
                .addPathPatterns("/updatePetLifeGoodsMessage")
                .addPathPatterns("/deletePetLifeGoodsMessage")
                .addPathPatterns("/updateFosterMessageByYes")
                .addPathPatterns("/updateFosterMessageByNo")
                .addPathPatterns("/updatePetManagement")
                .addPathPatterns("/updateLifeGoodsManagement")
                .addPathPatterns("/uploadPet")
                .addPathPatterns("/uploadLifeGoods")
                .excludePathPatterns("/user")
                .excludePathPatterns("/admin")
                .excludePathPatterns("/index.html")
//                .excludePathPatterns("/userRegistered")
//                .excludePathPatterns("/showIndent.html")
                .excludePathPatterns("/")
        ;
    }
}